package inner;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/11/13
 * Time: 9:48
 * Description:
 */
/*class OutClass {
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    public void func() {
        //static final int a  =10;
        //int data1 = 10;
    }

    *//**
     * 实例内部类：【实例的 “成员”】
     * 1、在实例内部类当中，为什么不能定义静态的成员变量? 需要定义一个在编译的时候，就确定的。
     * 2、获取实例内部类的对象：
     * OutClass outClass = new OutClass();
     * OutClass.InnerClass innerClass = outClass.new InnerClass();
     * 3、实例内部类当中，会包含外部类的this
     * 4、生成的实例内部类，类名是外部类$内部类名.class
     * 5、实例内部类，开销比较大。每次获取实例内部类对象，必须有一个外部类对象。
     *//*
    class InnerClass {
        public int data1 = 99;
        public int data4 = 4;
        private int data5 = 5;
        public static final int data6 = 6;

        //public OutClass out = new OutClass();

        public void func() {
            System.out.println("InnerClass::func()");
            //System.out.println(out.data1);
            System.out.println(this.data1);
            System.out.println(OutClass.this.data1);
            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
}*/
class OutClass {
    public int data1 = 1;
    public int data2 = 2;
    public static int data3 = 3;

    /**
     * 静态内部类：【静态的 “成员”】
     * 1、如何获取静态内部类的实例对象
     *    OutClass.InnerClass innerClass = new OutClass.InnerClass();
     * 2、如何访问 静态内部类当中，外部类的实例数据成员？
     *
     */
    static class InnerClass {
        public int data1 = 99;
        public int data4 = 4;
        private int data5 = 5;
        public static  int data6 = 6;

        public OutClass out = new OutClass();

        public void func() {
            System.out.println("InnerClass::func()");
            System.out.println(this.data1);
            System.out.println(out.data1);
            System.out.println(out.data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
}

class Out {
    public void func(){
        System.out.println("out::func()!");
    }
}
public class Test {

    public static void main(String[] args) {
        int c = 199;
        //new Out();匿名对象
        new Out(){
            int a = 10;
            //a = 99;
            //c = 888;
            @Override
            public void func() {
                System.out.println("匿名内部类的func()");
                System.out.println(a);
                System.out.println(c);
            }
        }.func();
    }

    public static void main2(String[] args) {

        OutClass.InnerClass innerClass = new OutClass.InnerClass();
        innerClass.func();

    }
    /*public static void main1(String[] args) {
        OutClass outClass = new OutClass();
        OutClass.InnerClass innerClass = outClass.new InnerClass();
        innerClass.func();
    }*/
}
